<?php

namespace app\common\model;

use think\Model;

class Topic extends Model
{
    public function gethotlist()
    {
        return $this->where(['type' => '1'])->limit(10)->select();
    }
    // 关联文章表
    public function post()
    {
        return $this->belongsToMany('Post','topic_post');
    }

    public function getPost()
    {
        $param = request()->param();
        $list = $this->get($param['id'])->post()->with(['user' => function($query){
            return $query->field(['username','userpic','id']);
        },'images' => function($query){
            return $query->field('url')->hidden(['pivot']);
        },'share'])->page($param['page'],10)->select();
        return $list;
    }
    // 搜索
    public function Search()
    {
        $param = request()->param();
        return self::where('title','like','%'.$param['keyword'].'%')->page($param['page'],10)->select();
    }
}
  